<?xml version="1.0"?>
<xsl:stylesheet version="1.0" 
                xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                xmlns:a="http://www.w3.org/2005/Atom"
                xmlns:ac="http://ionrock.org/ns/xsltemplate"
                xmlns:dyn="http://exslt.org/dynamic"
                xmlns:xh="http://www.w3.org/1999/xhtml"
                xmlns:f="http://xmlns.4suite.org/ext" 
                xmlns:func="http://exslt.org/functions"
                xmlns="http://www.w3.org/1999/xhtml"
                extension-element-prefixes="func f"
                exclude-result-prefixes="ac xh dyn f a func #default">

  <xsl:output method="html" omit-xml-declaration="yes" indent="yes" />

  <xsl:param name="ac:openid" />
  <xsl:param name="ac:base_url">/</xsl:param>

  <xsl:param name="ac:location" />
  <xsl:param name="ac:collection_uri" />
  <xsl:param name="ac:form_action">.</xsl:param>
  <xsl:param name="ac:atom_title" />
  <xsl:param name="ac:atom_content" />
  <xsl:param name="ac:atom_summary" />
  <xsl:param name="ac:atom_slug" />
  <xsl:param name="ac:atom_updated" />
  <xsl:param name="ac:atom_published" />
  <xsl:param name="ac:err_atom_title" />
  <xsl:param name="ac:err_atom_content" />
  <xsl:param name="ac:err_atom_updated" />
  <xsl:param name="ac:check_params">Nope not working</xsl:param>

  <xsl:template match="/">
    <html xmlns="http://www.w3.org/1999/xhtml">
      <head>
        <title>Atom Publishing Protocol Client</title>
        <xsl:variable name="css" 
                      select="concat($ac:base_url, 'static/css/styles.css')" />
        <link rel="stylesheet" type="text/css" href="{$css}" />
        <xsl:variable name="tiny-mce" 
                      select="concat($ac:base_url, 
                                     'static/js/tiny_mce/tiny_mce.js')" />
        <script type="text/javascript" src="{$tiny-mce}">
          <xsl:text> </xsl:text>
        </script>
        <xsl:variable name="tiny-mce-init" 
                      select="concat($ac:base_url, 
                                  'static/js/tiny_mce_init.js')" />
        <script type="text/javascript" src="{$tiny-mce-init}">
          <xsl:text> </xsl:text>
        </script>
      </head>
      <body>
        <div id="content-block">
          <div id="header-block">
            <h4>WSGIAppClient</h4>
            <div class="subheading">An Atom Publishing Protocol Client</div>
            <div class="breadcrumbs">
              <a href="{ac:this-base-url()}">home</a> &#8594;
              create
            </div>
          </div>
          <div id="body-block">
            <xsl:if test="$ac:location">
              <div class="result">
                Created <a href="{$ac:location}"><xsl:value-of select="$ac:location" /></a>!
              </div>
              <hr />
            </xsl:if>
            <xsl:apply-templates select="//a:entry" />
          </div>
        </div>
        <xsl:message>
          <xsl:copy-of select="." />
        </xsl:message>
      </body>
    </html>
  </xsl:template>
  
  <xsl:template match="a:entry">
    <form action="{$ac:form_action}" method="POST" enctype="multipart/form-data">
      <input type="hidden" name="collection_uri" value="{$ac:collection_uri}" />
      <fieldset id="main">
        <legend>Add an Entry</legend>
        <input type="submit" name="submit" value="Submit" />

        <div class="text-input">
          <label for="atom_title">
            <xsl:if test="$ac:err_atom_title">
              <span class="error_msg"><xsl:value-of select="$ac:err_atom_title" /></span>
            </xsl:if>Title
          </label>
          <input type="text" name="atom_title" value="{$ac:atom_title}" />
        </div>

        <div class="text-input">
          <label for="atom_slug">Slug</label>
          <input type="text" name="atom_slug" value="{$ac:atom_slug}" />
        </div>

        <div class="textarea-input">
          <label for="atom_content">
            <xsl:if test="$ac:err_atom_content">
              <span class="error_msg"><xsl:value-of select="$ac:err_atom_content" /></span>
              </xsl:if>Content
          </label>
          <textarea name="atom_content" rows="20" cols="80"><xsl:value-of select="$ac:atom_content" /><xsl:text> </xsl:text>
          </textarea>
        </div>
        <div class="textarea-input">
          <label for="atom_summary">Summary</label><br />
          <textarea name="atom_summary" rows="10" cols="80">
            <xsl:value-of select="$ac:atom_summary" /><xsl:text> </xsl:text>
          </textarea>
        </div>
      </fieldset>
    </form>
  </xsl:template>
  
  <xsl:template name="collection-info">
    <!--
        <fieldset>
        <legend>Collection</legend>
        <div>
        <label for="collection_url">Collection URL</label>
        <input type="text" name="collection_url" value="${collection_url}" />
        <br />
        <label for="collection_username">Username:</label>
        <input type="text" name="collection_username" value="${collection_username}" />
        <br />
        <label for="collection_password">Password:</label>
        <input type="password" name="collection_password" value="${collection_password}" />
        </div>
        </fieldset>
    -->
  </xsl:template>

  <xsl:template match="node()">
    <xsl:copy>
      <xsl:copy-of select="@* | text()" />
      <xsl:apply-templates />
    </xsl:copy>
  </xsl:template>

  <func:function name="ac:this-base-url">
    <xsl:param name="path" />
    <func:result select="f:resolve-url(f:resolve-url($ac:base_url, $ac:openid), $path)" />
  </func:function>
</xsl:stylesheet>